package com.coincalf.mapper;

import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import com.coincalf.entity.Account;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户财产记录 Mapper 接口
 * </p>
 *
 * @author qiang
 * @since 2018-05-12
 */
public interface AccountMapper extends BaseMapper<Account> {

    Account selectByUserAndCoinName(@Param("userId") long userId,
                                    @Param("coinName") String coinName);

    /**
     * 冻结账户资金
     *
     * @param accountId 资金账户ID
     * @param amount    冻结金额
     * @return
     */
    int lockAmount(@Param("accountId") long accountId, @Param("amount") BigDecimal amount);

    /**
     * 解冻账户资金
     *
     * @param accountId 资金账户ID
     * @param amount    解冻金额
     * @return
     */
    int unlockAmount(@Param("accountId") long accountId, @Param("amount") BigDecimal amount);

    /**
     * 增加账户资金
     *
     * @param accountId 资金账户ID
     * @param amount    增加金额
     * @return
     */
    int addAmount(@Param("accountId") long accountId, @Param("amount") BigDecimal amount);

    /**
     * 扣减账户资金
     *
     * @param accountId 资金账户ID
     * @param amount    扣减金额
     * @return
     */
    int subtractAmount(@Param("accountId") long accountId, @Param("amount") BigDecimal amount);

    /**
     * 根据币种Id和用户名称查询资金账户
     *
     * @param coinId   币种Id
     * @param userName 用户名称
     * @return
     */
    List<Account> selectAccountByNames(Pagination pagination,
                                       @Param("coinId") long coinId,
                                       @Param("userName") String userName,
                                       @Param("agencyUserId") long agencyUserId,
                                       @Param("createTime") String createTime,
                                       @Param("parentId") long parentId);


    List<Map<String, Object>> selectAllLevelUser(@Param("agencyUserId") long agencyUserId);


    Map<String, Object> selectUsdtAccountTotal(@Param("agencyUserId") long agencyUserId);

    Map<String, Object> selectBtcAccountTotal(@Param("agencyUserId") long agencyUserId);

    int withdrawalsAmount(@Param("id") long id, @Param("increment") BigDecimal increment, @Param("version") long version);

    /**
     * 保存用户充值地址
     *
     * @param id      资金账户主键
     * @param address 钱包地址
     */
    void setRechargeAddress(@Param("id") Long id, @Param("address") String address);

    /**
     * 查询用户所有USDT可用余额
     *
     * @param userId
     * @return
     */
    public BigDecimal getBalanceUsdt(@Param("userId") Long userId);

    public Account getBalanceAndId(@Param("userId") Long userId, @Param("coinId") Long coinId);

    /**
     * 冻结账户资金
     *
     * @param accountId 资金账户ID
     * @param amount    冻结金额
     * @return
     */
    int lockBalance(@Param("accountId") long accountId, @Param("amount") BigDecimal amount);
}
